<div class="alert">
<?php
require_once('includes/user_manage.php');

$user->isAdmin or exit("Área reservada a administradores");

if (isset($_POST["item_id"])) {
	$my_item=new admin_item();
	$my_item->id=$_POST["item_id"];

	if ($my_item->id>0) {
		$removed=$my_item->db_delete();
		if ($removed) {
		?>
			Se ha borrado el producto.
		<?php
		}
		else {
		?>
			Error desconocido.
		<?php
		}
	}
?>

<script type="text/javascript">
var itemId=<?php print $_POST["item_id"]; ?>;
	var catalogPointer=myCatalog;
	catalogPointer=catalogPointer.moveToChildren("selected");
	if (catalogPointer.myCategory.selected) {
		catalogPointer=catalogPointer.moveToChildren("selected");
	}
	var newItems=new Array();
	for (var i in catalogPointer.items) {
		if (catalogPointer.items[i].id != itemId) newItems.push(catalogPointer.items[i]);
	}
	catalogPointer.items=newItems;
	
	catalogPointer.refreshItemsListView("containerItems");

window.setTimeout(removeAlert,2000,document.getElementById('delItem'));
function removeAlert(alert) {
	alert.parentNode.removeChild(alert);
}
</script>
<?php
}
else {
?>
	<p id="alertMsg"></p>
	<form method="post" action="?section=del_item" myFor="delItem" id="delItemForm">
	<input type="hidden" value="<?php print $_GET["item_id"]; ?>" name="item_id">
	<table class="mytable">
		<tr>
			<td><input type="button" value="No borrar" myFor="delItem"></td>
			<td><input type="submit" value="Borrar" name="submitButton"></td>
		</tr>
	</table>
	</form>
<script type="text/javascript">
var itemId=<?php print $_GET["item_id"]; ?>;

	var catalogPointer=myCatalog;
	catalogPointer=catalogPointer.moveToChildren("selected");
	if (catalogPointer.myCategory.selected) {
		catalogPointer=catalogPointer.moveToChildren("selected");
	}
	for (var i in catalogPointer.items) {
		if (catalogPointer.items[i].id==itemId) {
			var itemPointer=catalogPointer.items[i];
			break;
		}
	}
var myMsg=document.getElementById("alertMsg");

	var alertMsg="¿Está seguro de querer borrar el producto "+ itemPointer.name + "?";
	myMsg.innerHTML=alertMsg;
</script>
<?php
}
?>
</div>